package controller;

import java.io.IOException;

import javax.servlet.ServletException;

import model.User;
import model.UserDAO;

import com.dncompute.marrow.Controller;

/**
 * 
 * Access at:
 * http://localhost:8888/advOfy/createUser?id=123&name=John&gender=male
 * 
 * This is a controller which is an evolution of BasicC.
 * 
 * It works much like BasicC, except it takes advantage of 
 * custom method calling based on the endpoint path
 * 
 * @author noelb
 *
 */
public class AdvOfy extends Controller {
	
	private static final long serialVersionUID = 1L;
	
	
	public void createUser() throws IOException, ServletException	{
		
		//Create the user
		User user = new User();
		user.id = Long.parseLong( req.getParameter("id") );
		user.name = req.getParameter("name");
		user.gender = req.getParameter("gender");
		UserDAO.get().putUser( user );
		
		//Save the model to the request
		req.setAttribute("user", user);
		
		//Forward to the display
		forward("/view/advuser.jsp");
		
	}
	
	
	public void displayUser() throws IOException, ServletException	{
		
		//Get the user
		User user = UserDAO.get().getUser( Long.parseLong( req.getParameter("id") ) );
		
		//Save the model to the request
		req.setAttribute("user", user);
		
		//Forward to the display
		forward("/view/advuser.jsp");
		
	}
	
	
}
